<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="支付方式名称" prop="payMethodName">
      <el-input v-model="dataForm.payMethodName" placeholder="支付方式名称"></el-input>
    </el-form-item>
 <!--   <el-form-item label="面额" prop="payFaceValue">
      <el-input v-model="dataForm.payFaceValue" placeholder="面额"></el-input>
    </el-form-item>
    <el-form-item label="商家实收" prop="sellerActualGet">
      <el-input v-model="dataForm.sellerActualGet" placeholder="商家实收"></el-input>
    </el-form-item>
    <el-form-item label="单次限用" prop="singleUseRestriction">
      <el-input v-model="dataForm.singleUseRestriction" placeholder="单次限用"></el-input>
    </el-form-item> -->
  <!--  <el-form-item label="允许会员卡使用" prop="allowMember">
		<el-radio v-model="dataForm.allowMember" label="1">允许</el-radio>
		<el-radio v-model="dataForm.allowMember" label="2">不允许</el-radio>
    </el-form-item>
    <el-form-item label="是否可找零" prop="giveChangeStatus">
		<el-radio v-model="dataForm.giveChangeStatus" label="1">是</el-radio>
		<el-radio v-model="dataForm.giveChangeStatus" label="2">否</el-radio>
    </el-form-item> -->
    <el-form-item label="充值是否可用" prop="rechargeStatus">
      <el-radio v-model="dataForm.rechargeStatus" label="1">是</el-radio>
      <el-radio v-model="dataForm.rechargeStatus" label="2">否</el-radio>
    </el-form-item>
    <!-- <el-form-item label="状态" prop="status">
      <el-radio v-model="dataForm.status" label="1">正常</el-radio>
      <el-radio v-model="dataForm.status" label="2">禁用</el-radio>
    </el-form-item>
    <el-form-item label="系统内置" prop="sysBuiltIn">
      <el-radio v-model="dataForm.sysBuiltIn" label="1">是</el-radio>
      <el-radio v-model="dataForm.sysBuiltIn" label="2">否</el-radio>
    </el-form-item> -->
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" :disabled="disabledSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
				disabledSubmit:false,
        dataForm: {
          payMethodId: 0,
          payMethodName: '',
          sellerId: '',
          paySortId: '',
          payFaceValue: '',
          sellerActualGet: '',
          singleUseRestriction: '',
          allowMember: '',
          giveChangeStatus: '',
          rechargeStatus: '1',
          status: '',
          sysBuiltIn: '',
          remark: ''
        },
        dataRule: {
          payMethodName: [
            { required: true, message: '支付方式名称不能为空', trigger: 'blur' }
          ],
          sellerId: [
            { required: true, message: '租户不能为空', trigger: 'blur' }
          ],
          paySortId: [
            { required: true, message: '支付分类ID不能为空', trigger: 'blur' }
          ],
          payFaceValue: [
            { required: true, message: '面额不能为空', trigger: 'blur' }
          ],
          sellerActualGet: [
            { required: true, message: '商家实收不能为空', trigger: 'blur' }
          ],
          singleUseRestriction: [
            { required: true, message: '单词限用不能为空', trigger: 'blur' }
          ],
          allowMember: [
            { required: true, message: '允许会员卡使用（1允许2不允许）不能为空', trigger: 'blur' }
          ],
          giveChangeStatus: [
            { required: true, message: '是否可找零(1可2不可)不能为空', trigger: 'blur' }
          ],
          rechargeStatus: [
            { required: true, message: '充值是否可用(1可2不可)不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态(1正常2禁用)不能为空', trigger: 'blur' }
          ],
          sysBuiltIn: [
            { required: true, message: '系统内置(1是2否)不能为空', trigger: 'blur' }
          ],
          // remark: [
          //   { required: true, message: '备注不能为空', trigger: 'blur' }
          // ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.payMethodId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.payMethodId) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstorepaymethod/info/${this.dataForm.payMethodId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.payMethodName = data.tStorePayMethod.payMethodName
                this.dataForm.sellerId = data.tStorePayMethod.sellerId
                this.dataForm.paySortId = data.tStorePayMethod.paySortId
                this.dataForm.payFaceValue = data.tStorePayMethod.payFaceValue
                this.dataForm.sellerActualGet = data.tStorePayMethod.sellerActualGet
                this.dataForm.singleUseRestriction = data.tStorePayMethod.singleUseRestriction
                this.dataForm.allowMember = data.tStorePayMethod.allowMember.toString()
                this.dataForm.giveChangeStatus = data.tStorePayMethod.giveChangeStatus.toString()
                this.dataForm.rechargeStatus = data.tStorePayMethod.rechargeStatus.toString()
                this.dataForm.status = data.tStorePayMethod.status.toString()
                this.dataForm.sysBuiltIn = data.tStorePayMethod.sysBuiltIn.toString()
                this.dataForm.remark = data.tStorePayMethod.remark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
				this.disabledSubmit = true
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstorepaymethod/${!this.dataForm.payMethodId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'payMethodId': this.dataForm.payMethodId || undefined,
                'payMethodName': this.dataForm.payMethodName,
                'sellerId': this.dataForm.sellerId,
                'paySortId': this.dataForm.paySortId,
                'payFaceValue': this.dataForm.payFaceValue,
                'sellerActualGet': this.dataForm.sellerActualGet,
                'singleUseRestriction': this.dataForm.singleUseRestriction,
                'allowMember': this.dataForm.allowMember,
                'giveChangeStatus': this.dataForm.giveChangeStatus,
                'rechargeStatus': this.dataForm.rechargeStatus,
                'status': this.dataForm.status,
                'sysBuiltIn': this.dataForm.sysBuiltIn,
                'remark': this.dataForm.remark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
											this.disabledSubmit = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.disabledSubmit = false
                this.$message.error(data.msg)
              }
            })
          }else {
            this.disabledSubmit = false
          }
        })
      }
    }
  }
</script>
